<div class="mainContent">
  <table class="data">
    <tr>
      <th>Name </th>
      <th>E-mail</th>
      <th>Superadmin?</th>
      <th>Admin Regions</th>
    </tr>
    <% for admin in @admins %>
    <tr>
      <td>
        <%= admin.name %>
      </td>
      <td>
        <%= admin.email %>
      </td>
      <td>
        <% if admin.id == current_user.id %>
          Yes
        <% elsif admin.has_role?("superadmin") %>
          Yes - <%= link_to "Remove", :action => :remove_role, :role_name => "superadmin",
                                      :user_id => admin.id %>
        <% else %>
          No - <%= link_to "Add", :action => :add_role, :role_name => "superadmin",
                                  :user_id => admin.id %>
        <% end %>
      </td>
      <td>
        <% if admin.has_role?("superadmin") %>
        N/A<% else %>
        <% @region_for = admin %>
        <span id="regions_for_<%=admin.id%>"><%= render :partial => "regions/admined" %>
        </span>
        
        <% form_tag 'javascript:void(0)' do %>
          <%= hidden_field_tag "user_" + admin.id.to_s, admin.id %>
          <%= select_tag "region_to_add_" + admin.id.to_s, "<option>-- Add Region --</option>" + options_from_collection_for_select(Region.find(:all), :id, :name) %>
        <% end %>
        
        <%= observe_field "region_to_add_" + admin.id.to_s, :update => 'regions_for_' + admin.id.to_s,
        :url => {:controller => 'regions', :action => 'add_to_user'},
        :with => "'region=' + encodeURIComponent(value) + '&user=' + $('user_#{admin.id}').value" %>
        <% end %>
      </td>
    </tr>
    <% end %>
  </table>
</div>
